<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>后台管理系统-保理软件</title>
    <meta name="keywords" content="保理软件,保理产品"/>
    <meta name="description" content="设置描述..."/>
    <meta name="author" content="DeathGhost"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <!--产品logo-->
    <link rel="icon" href="${pageContext.request.contextPath}/images/icon/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css"/>
    <script>var http = "${pageContext.request.contextPath}";</script>
    <!--jQuery v3.2.1-->
    <script src="${pageContext.request.contextPath}/javascript/jquery.js"></script>
    <!--滚动插件-->
    <script src="${pageContext.request.contextPath}/javascript/plug-ins/customScrollbar.min.js"></script>
    <!--统计插件-->
    <script src="${pageContext.request.contextPath}/javascript/plug-ins/echarts.min.js"></script>
    <!--弹框插件-->
    <script src="${pageContext.request.contextPath}/javascript/plug-ins/layerUi/layer.js"></script>
    <!--HTML编辑器插件-->
    <script src="${pageContext.request.contextPath}/editor/ueditor.config.js"></script>
    <!--HTML编辑器插件-->
    <script src="${pageContext.request.contextPath}/editor/ueditor.all.js"></script>
    <!--分页插件-->
    <script src="${pageContext.request.contextPath}/javascript/plug-ins/pagination.js"></script>
    <!--整个模板样式控制文件-->
    <script src="${pageContext.request.contextPath}/javascript/public.js"></script>
    <style>

        .form-group-col-2 .form-label {
            padding: 3px 0px !important;
            font-size: 12px !important;
            width: 115px;
            font-weight: bolder;
        }

        .form-group-col-2 .form-cont {
            margin-left: 125px;
            min-height: 33px;
        }

        .form-control {
            font-size: 12px !important;
            padding: 4px 15px !important;
        }

        #file {
            position: absolute;
            top: 0;
            right: 80px;
            z-index: 999;
            opacity: 0;
            width: 100px;
            height: 25px;
        }
    </style>
</head>
<body>

<!--软件主体内容-->
<main class="content mCustomScrollbar">
    <!--开始::内容-->
    <div class="page-wrap">
        <!--面包屑-->
        <section class="page-hd page-hd-top">
            <div class="breadcrumb">
                <ul>
                    <li><a href="#">权限管理</a><i class="icon-angle-right"></i></li>
                    <li>用户管理</li>
                </ul>
            </div>
        </section>
        <div class="clear mb-10">
            <button class="btn btn-secondary radius fr ml-15"
                    style="padding: 4px 15px!important;font-size: 12px!important;" onclick="addOrUpdateUser('0')">新增
            </button>
            <div class="fr input-group">
                <label class="mr-5 size-s">
                    人员名称：
                    <input type="text" class="form-control" placeholder="搜索..." style="width:290px;" id="condition">
                </label>
                <label class="mr-5 size-s">
                    状态：
                    <select id="status" style="width: 100px">
                        <option value="1001" selected>可用</option>
                        <option value="1000">禁用</option>
                        <option value="">全部</option>
                    </select>
                </label>
                <button class="btn btn-secondary radius" style="padding: 4px 15px!important;font-size: 12px!important;"
                        onclick="query()">
                    查询
                </button>
            </div>
        </div>
        <div id="context_div">

        </div>
    </div>
    <!--开始::结束-->
</main>
<div id="addOrUpdateUser" style="display: none">
    <div class="page-wrap">
        <div class="form-group-col-2">
            <div class="form-label">登录账号：</div>
            <div class="form-cont">
                <input type="hidden" id="userid" value="0">
                <input type="text" id="loginname" placeholder="登录账号" class="form-control form-boxed"
                       style="width: 360px">
            </div>
        </div>
        <div class="form-group-col-2">
            <div class="form-label">人员姓名：</div>
            <div class="form-cont">
                <input type="text" id="nickname" placeholder="人员姓名" class="form-control form-boxed"
                       style="width: 360px">
            </div>
        </div>
        <div class="form-group-col-2">
            <div class="form-label">账号状态：</div>
            <div class="form-cont">
                <select id="state" style="width:auto;" class="form-control">
                    <option value="1001">可用</option>
                    <option value="1000">禁用</option>
                </select>
            </div>
        </div>
        <div class="form-group-col-2">
            <div class="form-label">电话：</div>
            <div class="form-cont">
                <input type="text" id="mobile" placeholder="移动电话" class="form-control form-boxed" style="width: 360px">
            </div>
        </div>
        <div class="form-group-col-2">
            <div class="form-label">电子邮箱：</div>
            <div class="form-cont">
                <input type="text" id="email" placeholder="电子邮箱" class="form-control form-boxed" style="width: 360px">
            </div>
        </div>
        <div class="form-group-col-2">
            <div class="form-label">备注：</div>
            <div class="form-cont">
                <input type="text" id="description" placeholder="备注" class="form-control form-boxed"
                       style="width: 360px">
            </div>
        </div>
        <div style="clear: both;width: 25%;margin: 10px auto 15px;">
            <button class="btn btn-primary-outline btn-block" onclick="saveUser()">保存</button>
        </div>
    </div>
</div>

<%----%>
<div id="assignRole" style="display: none;">

</div>

<script>
    /*
     删除
     * */
    function deleteUser(id) {
        layer.confirm('您确定删除该账款吗？', {
            btn: ['确定', '取消']
        }, function () {
            $.get("${pageContext.request.contextPath}/usercontroller/users_deleteUser", {"sysid": id}, function (data) {
                layer.msg("*" + data.message);
                if (data.code == 1) {
                    go_page(1);
                }
            });
        });
    }

    //初始化
    function initdata(id) {
        var userid = $("#userid");
        var loginname = $("#loginname");
        var nickname = $("#nickname");
        var state = $("#state");
        var mobile = $("#mobile");
        var email = $("#email");
        var description = $("#description");
        if (id == 0) {
            userid.val(0);
            loginname.val("");
            nickname.val("");
            state.val("");
            mobile.val("");
            email.val("");
            description.val("");
        } else {
            $.get("${pageContext.request.contextPath}/usercontroller/users_getUser", {"sysid": id}, function (data) {

                if (data.code == 1) {
                    userid.val(data.data.sysid);
                    loginname.val(data.data.loginname);
                    nickname.val(data.data.nickname);
                    state.val(data.data.state);
                    mobile.val(data.data.mobile);
                    email.val(data.data.email);
                    description.val(data.data.description);
                } else {
                    layer.msg("*" + data.message);
                }
            });

        }
    }
    var layerwin;
    /*
     新增
     */
    function addOrUpdateUser(id) {
        var viveW = $(window).width() / 2;
        var viveH = $(window).height() - 60;
        initdata(id);
        var text = id == 0 ? "新增" : "修改";
        layerwin = layer.open({
            type: 1,
            skin: 'layui-layer-demo',
            title: text + "用户",
            closeBtn: 2,
            area: [viveW + 'px', '450px'],
            shade: [0.1, '#fff'],
            shadeClose: true, //开启遮罩关闭
            scrollbar: false,//屏蔽浏览器出现滚动条
            content: $('#addOrUpdateUser')
        });
    }

    function saveUser() {
        var userid = $("#userid").val();
        var loginname = $("#loginname").val();

        var nickname = $("#nickname").val();
        var state = $("#state").val();
        var mobile = $("#mobile").val();
        var email = $("#email").val();
        var description = $("#description").val();
        $.post("${pageContext.request.contextPath}/usercontroller/users_saveUser", {
            "sysid": userid,
            "loginname": loginname,
            "nickname": nickname,
            "state": state,
            "mobile": mobile,
            "email": email,
            "description": description
        }, function (data) {
            layer.msg("*" + data.message);
            if (data.code == 1) {
                layer.close(layerwin);
                go_page(1);
            }
        });
    }

    function query() {
        go_page(1);
    }

    function go_page(page) {
        //获取条件
        var condition = $("#condition").val();
        var status = $("#status").val();
        $.get("${pageContext.request.contextPath}/usercontroller/users_list", {
            "page": page,
            "status": status,
            "condition": condition
        }, function (data) {
            $("#context_div").html(data)
        });
    }

    function assignRole(id) {
        $.get("${pageContext.request.contextPath}/usercontroller/users_assignRole", {"sysid": id}, function (data) {
            $("#assignRole").html(data)
        });
        layerwin = layer.open({
            type: 1,
            skin: 'layui-layer-demo',
            title: "分配角色",
            closeBtn: 2,
            area: ['800px', '400px'],
            shade: [0.1, '#fff'],
            shadeClose: true, //开启遮罩关闭
            scrollbar: false,//屏蔽浏览器出现滚动条
            content: $('#assignRole')
        });
    }

    function saveRole() {
        var checks = $("input[type=checkbox]");
        var roleid = $("#role_check_id").val();

        var roids = "";
        checks.each(function (i, obj) {
            var flag = $(obj).prop('checked');
            var val = $(obj).val();

            if (flag) {
                if (roids == "") {
                    roids = val;
                } else {
                    roids += "," + val;
                }
            }
        });
        $.post("${pageContext.request.contextPath}/usercontroller/users_saveRole", {
            "sysid": roleid,
            "roids": roids
        }, function (data) {
            layer.msg("*" + data.message);
            if (data.code == 1) {
                layer.close(layerwin);
            }
        });
    }

    function changeStatus(id, status) {
        if (status == 1000) {
            status = 1001;
        } else {
            status = 1000;
        }
        $.post("${pageContext.request.contextPath}/usercontroller/users_changeStatus", {
            "sysid": id,
            "status": status
        }, function (data) {
            layer.msg("*" + data.message);
            if (data.code == 1) {
                go_page(1);
            }
        });
    }
    $(function () {
        go_page(1);
    });


</script>
</body>
</html>
